#include<bits/stdc++.h>
using namespace std;
int n,a[100005],t,m,l,x,ans=0;
struct carr{
int d;
int v;
int a;
};
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    struct carr car[100005];
    cin >> t;
    for(int k = 1;k <= t;k++)
    {
        cin >> n >> m >> l >> x;
        for(int j = 1;j <= n;j++)
        {
            cin >> car[j].d >> car[j].v >> car[j].a;
        }
        for(int i = 0;i < m;i++)
        {
            cin >>a[i];
        }
        for(int i = 0;i < n;i++)
        {
            if(car[i].v > x) ans++;
        }
        cout << ans << endl;
    }
}
